package com.iyoudoock.citymine.activity.order;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.iyoudoock.citymine.BaseActivity;
import com.iyoudoock.citymine.R;
import com.iyoudoock.citymine.adapter.OrderAdapter;
import com.iyoudoock.citymine.constants.Tab;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OrderCenterActivity extends BaseActivity {

    @BindView(R.id.tab_rg)
    RadioGroup tabRg;
    @BindView(R.id.order_vp)
    ViewPager orderVp;
    @BindView(R.id.nav_back_iv)
    ImageView navBackIv;

    private OrderAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_center);
        ButterKnife.bind(this);
    }

    @Override
    public void initNav() {
        super.initNav();
        hideActionbar();
        //setTitle("订单中心");
    }

    @Override
    public void init() {
        mAdapter = new OrderAdapter(getSupportFragmentManager(), Tab.getOrderPage());
        this.orderVp.setAdapter(mAdapter);

        this.orderVp.addOnPageChangeListener(mOnPageChangeListener);
        this.tabRg.setOnCheckedChangeListener(mOnCheckedChangeListener);
        this.navBackIv.setOnClickListener(this);

        ((RadioButton) this.tabRg.getChildAt(0)).setChecked(true);
    }


    /**
     * page changed listener
     */
    private ViewPager.OnPageChangeListener mOnPageChangeListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            ((RadioButton) tabRg.getChildAt(position)).setChecked(true);
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    };

    /**
     * tab changed listener
     */
    private RadioGroup.OnCheckedChangeListener mOnCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            int index = group.indexOfChild(findViewById(checkedId));
            orderVp.setCurrentItem(index);
        }
    };

    @Override
    public void onClick(View v) {
        onBackClick(v);
    }
}
